package com.cow;

import java.util.TimeZone;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Spring Boot 启动类
 * 
 * @author yangsj 
 */

@SpringBootApplication
@ServletComponentScan
@EnableRedisHttpSession
@EnableTransactionManagement 
@EnableDiscoveryClient
public class Application {
	@Value("${spring.profiles.active}")
	String profile;
	public static void main(String[] args) {	
		init();
		SpringApplication.run(Application.class, args);		
	}
	/*	
    @Bean
	public EmbeddedServletContainerFactory servletContainer() {
		TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
			@Override
			protected void postProcessContext(Context context) {

				SecurityConstraint securityConstraint = new SecurityConstraint();
				securityConstraint.setUserConstraint("CONFIDENTIAL");
				SecurityCollection collection = new SecurityCollection();
				collection.addPattern("/*");
				securityConstraint.addCollection(collection);
				context.addConstraint(securityConstraint);
			}
		};
		if(profile.equals("prod")){
			tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
		}
		
		return tomcat;
	}

	private Connector initiateHttpConnector() {
		Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
		connector.setScheme("http");
		connector.setPort(80);
		connector.setRedirectPort(443);
		connector.setSecure(false);
		return connector;
	}
	*/
	private static void init(){ 
		//设置时区
	    System.setProperty("user.timezone","Asia/Shanghai"); 
	    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
	}
	
}
